<template>
  <div>
    <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
      <div class="widget am-cf">
        <div class="widget-head am-cf">
          <div class="widget-title am-fl">宣传图配置</div>
        </div>
        <div class="widget-body  am-fr">

        <div class="am-u-sm-12 am-form ">
            <div class="am-u-sm-12 am-u-md-12 am-u-lg-3">
                <div class="am-form-group">
                    <select2  v-model="query.areaTeamId" :options="areaTeams">
                        <option value="">区域</option>
                    </select2>
                </div>
            </div>
            <div class="am-u-sm-12 am-u-md-12 am-u-lg-3 am-u-end">
              <div class="am-form-group">
                <button type="button" class="am-btn am-btn-default am-btn-success"
                        @click="search" ><span class="am-icon-search"></span>查询
                </button>
              </div>
            </div>

        </div>
        <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
            <div class="am-form-group">
                <button type="button" class="am-btn am-btn-default am-btn-success "  @click="$router.push('/main/online/addPublicPicture')">
                    <span class="am-icon-plus" ></span>&nbsp;新增
                </button>
            </div>
        </div>
          <div class="am-u-sm-12">
            <el-table
              :data="tableData"
              border
              stripe
              style="min-width: 100%">
              <el-table-column
                prop="areaTeamName"
                label="区域"
                min-width="100">
              </el-table-column>
              <el-table-column
                prop="page"
                label="页面"
                min-width="100">
                 <template scope="scope">
                  <div>
                    {{scope.row.page==='index'?'首页':''}}
                  </div>
                </template>
              </el-table-column>
              <el-table-column
                prop="position"
                label="位置"
                min-width="130">
              </el-table-column>
              <el-table-column
                prop="picUrl"
                label="图片"
                min-width="250">
              </el-table-column>
              <el-table-column
                prop="clickUrl"
                label="跳转链接"
                min-width="250">
              </el-table-column>
              <el-table-column
                prop="score"
                label="最后操作时间"
                min-width="165">
                <template scope="scope">
                  <div>
                    {{scope.row.updateDate | formatTime}}
                  </div>
                </template>
              </el-table-column>
              <el-table-column
                prop="creatorName"
                label="最后操作人"
                min-width="120">
              </el-table-column>
              <el-table-column
                label="操作"
                min-width="150">
                <template scope="scope">
                    <div>
                       <el-button size="small" @click="handleDelete(scope.row.adId)">删除</el-button>
                       <el-button size="small" @click="$router.push('/main/online/addPublicPicture?adId='+ scope.row.adId)">编辑</el-button>
                    </div>
                </template>
              </el-table-column>
            </el-table>
          </div>
          <div class="am-u-lg-12 am-cf">
            <div class="am-fr">
              <pagination v-bind:total="total" v-bind:pageNo="pageNo" v-bind:pageSize="pageSize"
                          @paging="loadTableData"/>
            </div>
          </div>
        </div>
      </div>
    </div>

  </div>
</template>

<script>

  import Pagination from '../base/Pagination'
  import io from '../../lib/io/index'

  export default{
    data: function () {
      return {
        multipleSelection: [],
        examPaperIds: [],
        measurementId: '',
        tableData: [],
        total: 0,
        pageSize: 10,
        pageNo: 1,
        query:{
            areaTeamId : window.config.areaTeams[0] && window.config.areaTeams[0].areaTeamId || '' ,
        }
      }
    },
    components: {
      Pagination
    },
    mounted: function () {
      $(window).smoothScroll()
    },
    created: function () {
      this.loadTableData(1)
    },
    computed:{
        areaTeams: function () {
        var options = ( this.$root.config.areaTeams || [] )
            .map(function (item) {
            return {value: item.areaTeamId, text: item.name}
            })
        return options
        },
    },
    methods: {
      handleDelete(adId) {
        var _this = this
        _this.$confirm('你确定要删除？',
          function () {
            io.post(io.delAdConfig, {
              adId: adId,
            }, function (ret) {
              if (ret.success) {
                _this.$toast('删除成功！')
                _this.loadTableData()
              } else {
                _this.$alert(ret.desc)
              }
            })
          });
      },
      handleLooking(examPaperId) {
        this.$refs.paperDetail.examPaperId = examPaperId
        this.$refs.paperDetail.show()
      },
      search:function(){
        this.loadTableData(1)
      },
      loadTableData: function (pageNo) {
        var _this = this
        _this.pageNo = pageNo || _this.pageNo || 1
        io.post(io.adConfigList, {
          areaTeamId: _this.query.areaTeamId,
          pageNo: _this.pageNo,
          pageSize: _this.pageSize,
        }, function (ret) {
          if (ret.success) {
            _this.total = ret.data.total
            _this.tableData = ret.data
          } else {
            _this.$alert(ret.desc)
          }
        })
      },
    }
  }
</script>
<style scoped lang="less">
  .red {
    color: red;
  }
  .content-tooltip {
    unicode-bidi: embed;
    white-space: pre;
    font-size: 14px;
    line-height: 1.5;
  }
</style>
